package com.yanqu.road.server.cmd.activity.memorypieces;

import com.yanqu.road.pb.activity.MemoryPiecesProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.memorypieces.MemoryPiecesModule;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.S_MEMORY_PIECES_LIGHT_UP, desc = "记忆碎片点亮")
public class MemoryPiecesLightUpCmd extends AbstractCommand {

    int index;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        MemoryPiecesProto.MemoryPiecesLightUpReqMsg reqMsg = MemoryPiecesProto.MemoryPiecesLightUpReqMsg.parseFrom(packet.getBytes());
        index = reqMsg.getIndex();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        ret = player.getModule(MemoryPiecesModule.class).piecesLightUp(index);
    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret != 0) {
            MemoryPiecesProto.MemoryPiecesLightUpRespMsg.Builder respMsg = MemoryPiecesProto.MemoryPiecesLightUpRespMsg.newBuilder();
            respMsg.setRet(ret);
            player.sendPacket(Protocol.U_MEMORY_PIECES_LIGHT, respMsg);
        }
    }
}
